<template>
    <div class="col606266">
        <el-row>
            <el-col :span="8">
                <el-form :model="distributorData1" status-icon
                    :rules="distributorRules1" ref="distributorData1" label-width="200px"
                >
                    <el-form-item label="启用级别：">
                        <el-radio-group v-model="distributorData1.classify">
                            <el-radio label="1">1级</el-radio>
                            <el-radio label="2">2级</el-radio>
                        </el-radio-group>
                    </el-form-item>
                    <!-- <el-form-item label="id：">
                        {{ distributorData1.id }}
                    </el-form-item>
                    <el-form-item label="name：">
                        {{ distributorData1.name }}
                    </el-form-item> -->
                    <el-form-item label="1级(上级)比例（百分比）：" prop="scale1">
                        <el-input v-model="distributorData1.scale1" size="small"
                            type="number"
                        ></el-input>
                    </el-form-item>
                    <el-form-item label="2级(上上级)比例（百分比）：" prop="scale2">
                        <el-input v-model="distributorData1.scale2" size="small"
                            type="number"
                        ></el-input>
                    </el-form-item>
                    <el-form-item label="提现门槛：" prop="threshold">
                        <el-input v-model="distributorData1.threshold" size="small"
                            type="number"
                        ></el-input>
                    </el-form-item>
                    <div class="colF56c6c mb22">
                        全部保留两位小数
                    </div>
                    <el-form-item>
                        <el-button type="primary" @click="subDistributor1"
                            size="small"
                        >
                            提交修改
                        </el-button>
                    </el-form-item>
                </el-form>
            </el-col>
        </el-row>
    </div>
</template>
<script>
import { getShareSetting, saveShareSetting } from '@s/api'
export default {
    data() {
        let scale1Check = (rule, value, callback) => {
          if (value === '') {
            callback(new Error('请输入1级比例'));
          } else {
            callback();
          }
        };
        let scale2Check = (rule, value, callback) => {
          if (value === '') {
            callback(new Error('请输入2级比例'));
          } else {
            callback();
          }
        };
        let thresholdCheck = (rule, value, callback) => {
          if (value === '') {
            callback(new Error('请输入提现门槛'));
          } else {
            callback();
          }
        };
        return {
            distributorData1: {
                classify: '', id: '', name: '', scale1: '', scale2: '', threshold: ''
            },
            distributorRules1: {
                scale1: [{ validator: scale1Check, trigger: 'blur' }],
                scale2: [{ validator: scale2Check, trigger: 'blur' }],
                threshold: [{ validator: thresholdCheck, trigger: 'blur' }],
            }
        }
    },
    mounted() {
        this.getDataList1();
    },
    methods: {
        getDataList1() {
            getShareSetting({
                token: this.$store.getters.token
            }).then(res => {
                this.distributorData1 = res.data;
            })
        },
        subDistributor1() {
            this.$refs['distributorData1'].validate(valid => {
                if (valid) {
                    this.$confirm('确定修改分销设置？', '提示', {
                        confirmButtonText: '确定', cancelButtonText: '取消', type: 'warning'
                    }).then(() => {
                        saveShareSetting({
                            token: this.$store.getters.token,
                            classify: this.distributorData1.classify,
                            threshold: this.distributorData1.threshold,
                            scale1: this.distributorData1.scale1,
                            scale2: this.distributorData1.scale2
                        }).then(res => {
                            this.$message({ type: "success", message: '修改成功' });
                        })
                    }).catch(() => { });
                }
            })
        }
    }
}
</script>